package activity;

import android.database.Cursor;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.administrator.ci_edit.R;

import java.text.SimpleDateFormat;
import java.util.Date;

import db.CipaiDatabaseHelper;

/**
 * Created by Administrator on 2017/7/24.
 */

public class MeiRiYiCiActivity extends AppCompatActivity{

    private TextView examnameTV;
    private TextView examcontentTV;
    private TextView date;
    private ImageView iv;

    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_meiriyici);

        examnameTV = (TextView)findViewById(R.id.examnameTV);
        examcontentTV = (TextView)findViewById(R.id.examcontentTV);
        iv = (ImageView)findViewById(R.id.meiriimg);

        SimpleDateFormat formatter = new SimpleDateFormat("dd");
        Date curDate = new Date(System.currentTimeMillis());//获取当前时间
        int zhongzi = Integer.parseInt(formatter.format(curDate));
        int imgzhongzi = zhongzi % 7;
        String img = "meiriyici"+imgzhongzi;
        if(imgzhongzi == 0){
            iv.setBackgroundResource(R.drawable.meiriyici5);
        }else if(imgzhongzi == 1){
            iv.setBackgroundResource(R.drawable.meiriyici1);
        }else if(imgzhongzi == 2){
            iv.setBackgroundResource(R.drawable.meiriyici2);
        }else if(imgzhongzi == 3){
            iv.setBackgroundResource(R.drawable.meiriyici3);
        }else if(imgzhongzi == 4){
            iv.setBackgroundResource(R.drawable.meiriyici4);
        }else if(imgzhongzi == 5){
            iv.setBackgroundResource(R.drawable.meiriyici5);
        }else if(imgzhongzi == 6){
            iv.setBackgroundResource(R.drawable.meiriyici6);
        }


        CipaiDatabaseHelper cipaiDatabaseHelper = new CipaiDatabaseHelper();
        Cursor cursor = cipaiDatabaseHelper.getExampleById(zhongzi);
        while (cursor.moveToNext()){
            String examname = cursor.getString(cursor.getColumnIndex("author"));
            String examcontent = cursor.getString(cursor.getColumnIndex("text"));
            examnameTV.setText(examname);
            examcontentTV.setText(examcontent);
        }
    }
}
